package com.huanglj.himalaya.data.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

import com.huanglj.himalaya.utils.Constants;
import com.huanglj.himalaya.utils.LogUtil;

import static com.huanglj.himalaya.utils.Constants.HISTORY_AUTHOR_NAME;
import static com.huanglj.himalaya.utils.Constants.HISTORY_COVER;
import static com.huanglj.himalaya.utils.Constants.HISTORY_DESCRIPTION;
import static com.huanglj.himalaya.utils.Constants.HISTORY_DURATION;
import static com.huanglj.himalaya.utils.Constants.HISTORY_ID;
import static com.huanglj.himalaya.utils.Constants.HISTORY_PLAY_COUNT;
import static com.huanglj.himalaya.utils.Constants.HISTORY_TB_NAME;
import static com.huanglj.himalaya.utils.Constants.HISTORY_TITLE;
import static com.huanglj.himalaya.utils.Constants.HISTORY_TRACK_ID;
import static com.huanglj.himalaya.utils.Constants.HISTORY_UPDATE_TIME;
import static com.huanglj.himalaya.utils.Constants.SUB_ALBUM_ID;
import static com.huanglj.himalaya.utils.Constants.SUB_AUTHOR_NAME;
import static com.huanglj.himalaya.utils.Constants.SUB_COVER_URL;
import static com.huanglj.himalaya.utils.Constants.SUB_DESCRIPTION;
import static com.huanglj.himalaya.utils.Constants.SUB_ID;
import static com.huanglj.himalaya.utils.Constants.SUB_PLAY_COUNT;
import static com.huanglj.himalaya.utils.Constants.SUB_TB_NAME;
import static com.huanglj.himalaya.utils.Constants.SUB_TITLE;
import static com.huanglj.himalaya.utils.Constants.SUB_TRACKS_COUNT;

public class XimalayaDBHelper extends SQLiteOpenHelper {

    private static final String TAG = "XimalayaDBHelper";
    public XimalayaDBHelper(@Nullable Context context) {
        //name:数据库名字,factory:游标工厂，version:版本名字
        super(context, Constants.DB_NAME, null,Constants.DB_VERSION_CODE);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        LogUtil.d(TAG,"onCreate...");
        //创建数据库
        //id,图片,标题,描述,播放数量,节目数量,作者名,专辑id
        String subTbSql = "create table "+SUB_TB_NAME+"("+SUB_ID+" integer primary key autoincrement," +
                " "+SUB_COVER_URL+" varchar, "+SUB_TITLE+" varchar," +
                ""+SUB_DESCRIPTION+" varchar, "+SUB_PLAY_COUNT+" integer, "+SUB_TRACKS_COUNT+" integer," +
                ""+SUB_AUTHOR_NAME+" varchar, "+SUB_ALBUM_ID+" integer);";
        String historyTbSql = "create table "+HISTORY_TB_NAME+"(" +
                ""+HISTORY_ID+" integer primary key autoincrement," +
                ""+HISTORY_TRACK_ID+" integer," +
                ""+HISTORY_TITLE+" varchar," +
                ""+HISTORY_COVER+" varchar," +
                ""+HISTORY_PLAY_COUNT+" integer," +
                ""+HISTORY_AUTHOR_NAME+" varchar," +
                ""+HISTORY_DURATION+" integer," +
                ""+HISTORY_UPDATE_TIME+" integer);";
        db.execSQL(subTbSql);
        db.execSQL(historyTbSql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
